package com.shopping.factory;

import com.shopping.strategy.BasePromotion;
import com.shopping.strategy.impl.CouponPromotionStrategy;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @author wdx
 * @desc 生成各种优惠策略的工厂
 * @date 2023/10/28
 */
public class PromotionFactory {

    private final static Map<String, BasePromotion> PROMOTION_STRATEGY = new HashMap<>();

    static {
        PROMOTION_STRATEGY.put(PromotionStrategyType.COUPON, new CouponPromotionStrategy());
    }

    private PromotionFactory() {
    }

    //    执行用户选择的策略
    public static Object doPromotion(String key, Object context) {
        BasePromotion basePromotion = PROMOTION_STRATEGY.get(key);
        if (basePromotion != null) {
            return basePromotion.doPromotion(context);
        }
        return context;
    }

    //    获取所有的策略
    public static Set<String> getAllPromotionStrategy() {
        return PROMOTION_STRATEGY.keySet();
    }

    interface PromotionStrategyType {
        String COUPON = "COUPON";
    }
}
